﻿using System;

namespace Com.OpenCode.DwgConvert.Model
{
    /// <summary>
    /// 抽象日志类
    /// </summary>
    public abstract class AbstractLogItem : ILogItem
    {
        public AbstractLogItem(string value)
        {
            Value = value;
            DateTime = DateTime.Now;
        }

        /// <summary>
        /// 日志类型
        /// </summary>
        public virtual LogType LogType { get; protected set; }

        /// <summary>
        /// 日志创建时间
        /// </summary>
        public virtual DateTime DateTime { get; protected set; }

        /// <summary>
        /// 日志内容
        /// </summary>
        public virtual string Value { get; set; }

        /// <summary>
        /// 追加日志信息
        /// </summary>
        /// <returns></returns>
        public virtual void Append(string value)
        {
            Value += value;
        }

        /// <summary>
        /// 重写ToString函数
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("{0} {1}: {2}", DateTimeUtils.FromatDateString(DateTime), FormatLogType(), Value);
        }

        /// <summary>
        /// 根据日志类型格式化显示日志
        /// </summary>
        /// <returns></returns>
        protected string FormatLogType()
        {
            switch (LogType)
            {
                case LogType.Info:
                    return "信息";
                case LogType.Wraing:
                    return "警告";
                case LogType.Error:
                    return "错误";
                default:
                    return "信息";
            }
        }
    }
}
